const express = require('express')
const app = express()
const cors = require('cors')
// 跨域
app.use(cors())
let messages = []


// 服务接受前端发送的消息
app.get('/sendmsg', (req, res) => {

    let text = req.query.text;
    let date = req.query.date;
    let nickname = req.query.nickname;
    let avatar = req.query.avatar

    messages.push({
        text,date,nickname,avatar
    })

    res.send({
        code:200,
        msg:"ok"
    })
  
})

// 客户端轮询服务端消息
app.get('/getmsg', (req, res) => {

    let lastMessage = messages[messages.length-1]
    res.send(lastMessage)

})


app.listen(3000, () => console.log("服务器启动。。。"))